package ai.hou.camera.util;

import android.media.ExifInterface;

import java.io.IOException;

/**
 * @author zhaoxiaolei
 * @date 2021/3/15 16:13
 */
public class FileUtils {

    public static int getImageRotation(String filePath) {
        int rotation = 0;
        try {
            ExifInterface exifInterface = new ExifInterface(filePath);
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
                rotation = 90;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
                rotation = 180;
            } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
                rotation = 270;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return rotation;
    }
}
